package game.display;

import game.MainController;
import game.Engine.Entity.Player;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class OverlayImage {
	public static final int OFFSET = (int)(MainController.displayEngine.getWidth()*.06);
	public static final double BACKGROUNDSTARTINGX = .045;
	public static final double STARTINGX = .05;
	public static final double BACKGROUNDSTARTINGY = .03;
	public static final double STARTINGY = .04;
	public static final double WIDTH = .05;
	public static final double BACKGROUNDWIDTH = .11;
	public static final double BACKGROUNDHEIGHT = .12;
	public static final double HEIGHT = .1;
	
	private static final int WHITE = 0;
	private static final int RED = 1;
	private static final int GREEN = 2;
	private static final int BLUE = 3;
	private static final int YELLOW = 4;
	
	private PowerUpDisplay white,red,green,blue,yellow;
	
	public OverlayImage(){
		white = new PowerUpDisplay(new Rectangle((int)(MainController.displayEngine.getWidth()*STARTINGX)+OFFSET*WHITE, (int)(MainController.displayEngine.getHeight()*STARTINGY), (int)(MainController.displayEngine.getWidth()*WIDTH), (int)(MainController.displayEngine.getHeight()*HEIGHT)),WHITE);
		red = new PowerUpDisplay(new Rectangle((int)(MainController.displayEngine.getWidth()*STARTINGX)+OFFSET*RED, (int)(MainController.displayEngine.getHeight()*STARTINGY), (int)(MainController.displayEngine.getWidth()*WIDTH), (int)(MainController.displayEngine.getHeight()*HEIGHT)),RED);
		green = new PowerUpDisplay(new Rectangle((int)(MainController.displayEngine.getWidth()*STARTINGX)+OFFSET*GREEN, (int)(MainController.displayEngine.getHeight()*STARTINGY), (int)(MainController.displayEngine.getWidth()*WIDTH), (int)(MainController.displayEngine.getHeight()*HEIGHT)),GREEN);
		blue = new PowerUpDisplay(new Rectangle((int)(MainController.displayEngine.getWidth()*STARTINGX)+OFFSET*BLUE, (int)(MainController.displayEngine.getHeight()*STARTINGY), (int)(MainController.displayEngine.getWidth()*WIDTH), (int)(MainController.displayEngine.getHeight()*HEIGHT)),BLUE);
		yellow = new PowerUpDisplay(new Rectangle((int)(MainController.displayEngine.getWidth()*STARTINGX)+OFFSET*YELLOW, (int)(MainController.displayEngine.getHeight()*STARTINGY), (int)(MainController.displayEngine.getWidth()*WIDTH), (int)(MainController.displayEngine.getHeight()*HEIGHT)),YELLOW);
	}

	public void update(Graphics g) {
		//Draws the background of the powerUps
		updateBackgroundPowerUp(g,OFFSET*WHITE,WHITE);
		updateBackgroundPowerUp(g,OFFSET*RED,RED);
		updateBackgroundPowerUp(g,OFFSET*GREEN,GREEN);
		updateBackgroundPowerUp(g,OFFSET*BLUE,BLUE);
		updateBackgroundPowerUp(g,OFFSET*YELLOW,YELLOW);
		
		//Updates the powerUps according to time left
		updatePowerUps(g);
		
		g.setColor(Color.WHITE);

		//Updates the alienCount
		g.drawString("Alien Count: "+ MainController.gameEngine.getCurrentAlienCount(), (int)(MainController.displayEngine.getWidth()*.85), (int)(MainController.displayEngine.getHeight()*.05));

      Player p = MainController.gameEngine.getPlayer(MainController.getID());
      if (p != null) {
		//Updates the total Points
		g.drawString("Total Points: "+p.getTotalPoints(), (int)(MainController.displayEngine.getWidth()*.85), (int)(MainController.displayEngine.getHeight()*.1));
      }
	}
	
	public void updatePowerUps(Graphics g){
		white.update(g,Color.white);
		red.update(g,Color.red);
		green.update(g,Color.green);
		blue.update(g,Color.blue);
		yellow.update(g,Color.yellow);
	}
	
	private void updateBackgroundPowerUp(Graphics g, int offSet, int magicType){
		//Draws a white square indicating the powerup that is selected
		if(MainController.gameEngine.players.get(MainController.getID()).getCurrentPowerUpSelected() == magicType)g.setColor(Color.white);
		else g.setColor(Color.black);//Sets and draws the background black
			
		g.fillRect((int)(MainController.displayEngine.getWidth()*BACKGROUNDSTARTINGX)+offSet, (int)(MainController.displayEngine.getHeight()*BACKGROUNDSTARTINGY), (int)(MainController.displayEngine.getWidth()*.06), (int)(MainController.displayEngine.getHeight()*BACKGROUNDHEIGHT));
	}
}
